package com.tw101.module1;

public class Triangle {
    public static String horizontalLine(int lines) {
        StringBuilder lineBuilder = new StringBuilder();
        for (int i = 0; i < lines; i++) {
            lineBuilder.append("*");
        }
        return lineBuilder.toString();
    }

    public static String verticalLine(int lines) {
        StringBuilder lineBuilder = new StringBuilder();
        for (int i = 0; i < lines; i++) {
            if(i != 0) {
                lineBuilder.append("\n");
            }
            lineBuilder.append("*");
        }
        return lineBuilder.toString();
    }

    public static String rightTriangle(int lines) {
        StringBuilder lineBuilder = new StringBuilder();
        for (int i = 1; i <= lines; i++) {
            if(i != 1) {
                lineBuilder.append("\n");
            }
            lineBuilder.append(horizontalLine(i));
        }
        return lineBuilder.toString();
    }

    public static String isoscelesTriangle(int lines) {
        StringBuilder lineBuilder = new StringBuilder();
        for (int i = 0, currentLines = 1; i < lines; i++, currentLines += 2) {
            if(i != 0) {
                lineBuilder.append("\n");
            }
            lineBuilder.append(String.format("%" + (lines - i + currentLines) + "s",
                    horizontalLine(currentLines)));
        }
        return lineBuilder.toString();
    }

}
